﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using whatpricemyhouse.LINQ;

namespace whatpricemyhouse
{
    public partial class SearchPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request.QueryString["queryString"]))
            {
                String queryString = Request.QueryString["queryString"];
                    DataControllerDataContext dcdc = new DataControllerDataContext();
                    var regionList = (from r in dcdc.suburbs
                                     where r.area.Contains(queryString)
                                     orderby r.area
                                      select r.area).Distinct();
                    int i = 0;
                foreach(var region in regionList){
                    Response.Write("<a href='?c="+region+"' OnClick='' onmouseover='mouseOver(this)' onmouseout='mouseOut(this)'>" + region + "</a><br />");
                     if (i > 5) {
                         break;
                     }
                     i++;
                }

                if (i == 0) {
                    Response.Write("No result!");
                }
            }
        }
    }
}